//


import UIKit

protocol WP_FieldTableViewDelegate:NSObjectProtocol {
    func SendIndexCell(index:NSInteger,obj:String)
}

class WP_FieldTableViewCell: UITableViewCell {
    
    var titleLabel:UILabel!
    var tfield:UITextField!
    var lineView:UIView!
    var index:NSInteger!
    var IndexBlock:(()->())?
    weak var delegate:WP_FieldTableViewDelegate?
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: .default, reuseIdentifier: reuseIdentifier)
        
        setupCell()
    }
    
    func setupCell() {
        
        titleLabel = UILabel(frame: CGRect(x: kRatioWidth(12), y: kRatioHeight(10), width: kRatioWidth(400), height: kRatioHeight(25)))
        titleLabel.textColor = UIColorFromHex(0xFF6347)
        titleLabel.font = FontPFBold(18)
        titleLabel.text = "work content of this mooth"
        self.contentView.addSubview(titleLabel)
        
        tfield = UITextField.init(frame: CGRect(x: kRatioWidth(12), y: titleLabel.frame.maxY+kRatioHeight(20), width: kScreenWidth-kRatioWidth(50), height: kRatioHeight(30)))
        tfield.placeholder = ""
        tfield.font = FontPFRegular(16)
        tfield.textColor = UIColorFromHex(0xc9c9cd)
        tfield.text = ""
        tfield.keyboardType = .emailAddress
        tfield.addTarget(self, action: #selector(fieldClick(sender:)), for: .editingChanged)
        self.contentView.addSubview(tfield)
        
        lineView = UIView.init(frame: CGRect(x: kRatioWidth(12), y: tfield.frame.maxY, width: kScreenWidth-kRatioWidth(24), height: 1))
        lineView.backgroundColor = UIColorFromHex(0xeaeaea)
        self.contentView.addSubview(lineView)
        
    }
    
    @objc func fieldClick(sender:UITextField)  {
        
        delegate?.SendIndexCell(index: index, obj: sender.text!)
    }
    
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}
